import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBConnection {

    private static final String DRIVER_CLASS_NAME;
    private static final String URL;
    private static final String USERNAME;
    private static final String PASSWORD;

    static{

        Properties prop=new Properties();
        try {
            prop.load(DBConnection.class.getResourceAsStream("/jdbc.properties"));
        } catch (IOException e) {
            System.out.println("jdbc.properties file not found.message is "+e.getMessage());
        }
        DRIVER_CLASS_NAME=prop.getProperty("jdbc.driverClassName");
        URL=prop.getProperty("jdbc.url");
        USERNAME=prop.getProperty("jdbc.userName");
        PASSWORD=prop.getProperty("jdbc.password");
        try {
            Class.forName(DRIVER_CLASS_NAME);
        } catch (ClassNotFoundException e) {
            System.out.println("Class file not found.message is "+e.getMessage());
        }
    }

    public static Connection getConnection(){
        Connection connection= null;
        try {
            connection = DriverManager.getConnection(URL,USERNAME,PASSWORD);
        } catch (SQLException e) {
            System.out.println("database connection error.message is "+e.getMessage());
        }
        return connection;
    }

    public void closeConnection(){}

}
